package com.example.demo.controller;

import com.example.demo.entity.Wallet;
import com.example.demo.entity.WalletRecord;
import com.example.demo.service.WalletService;
import com.example.demo.vo.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import jakarta.annotation.Resource;
import lombok.NonNull;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author DLX
 * @data 2024/6/13 14:23
 */
@RestController
@RequestMapping("/wallet")
public class WalletController
{
    @Resource
    public WalletService wallerService;

    @Operation(summary = "根据用户id查询钱包")
    @GetMapping("/selectWallet")
    public Wallet SelectWalletByUid(@Parameter(name = "userId", description = "用户id", required = true) @NonNull Long userId)
    {
        return wallerService.SelectWalletByUid(userId);
    }

    @Operation(summary = "根据用户id查询钱包")
    @GetMapping("/selectWalletRecord")
    public List<WalletRecord> SelectWalletRecordByUid(@Parameter(name = "userId", description = "用户id", required = true) @NonNull Long userId)
    {
        return wallerService.SelectWalletRecordByUid(userId);
    }

    @Operation(summary = "充值金币")
    @PostMapping("/addMoney")
    public Result addMoney(
            @Parameter(name = "userId", description = "用户id", required = true) @NonNull Long userId,
            @Parameter(name = "money", description = "充值金额", required = true) @NonNull Double money
    ){
        wallerService.addMoney(userId,money);
        return Result.ok();
    }

    @Operation(summary = "根据用户id创建钱包")
    @PostMapping("/createWallet")
    public Wallet createWalletByUid(@Parameter(name = "userId", description = "用户id", required = true) @NonNull Long userId){
        return wallerService.createWalletByUid(userId);
    }

}
